#!/usr/bin/env python

import wx

class Frame(wx.Frame):
    '''Frame class
    
    @author Julot <andy.julot@gmail.com>
    @since Saturday, February 11, 2012. 01:02 PM'''
    
    _busyInfo = None
    
    def busyCursor(self):
        self.SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
        
    def busyInfo(self, message):
        self.busyCursor()
        self._busyInfo = wx.BusyInfo(message, self)
        wx.Yield()
        return self._busyInfo
    
    def idle(self):
        if self._busyInfo: del self._busyInfo
        if self._progressDialog: self._progressDialog.Destroy()
        cursor = wx.StockCursor(wx.CURSOR_ARROW)
        self.SetCursor(cursor)
    
    _progressDialog = None
    
    def progressDialog(self, title, message, maximum=100,
                       style=wx.PD_AUTO_HIDE|wx.PD_APP_MODAL):
        cursor = wx.StockCursor(wx.CURSOR_WAIT)
        self.SetCursor(cursor)
        self._progressDialog = wx.ProgressDialog(title, message, maximum, self,
                                                 style)
        self._progressDialog.Show()
        return self._progressDialog
    
    def updateProgress(self, value, message):
        return self._progressDialog.Update(value, message)
    
    def resumeProgress(self):
        self._progressDialog.Resume()
    
    def messageDialog(self, message, caption, style=wx.OK,
                      pos=wx.DefaultPosition):
        dialog = wx.MessageDialog(self, message, caption, style, pos)
        result = dialog.ShowModal()
        dialog.Destroy()
        return result
    
    def fileDialog(self, message="Choose a file", defaultDir="",
                   defaultFile="", wildcard="*.*", style=wx.FD_DEFAULT_STYLE,
                   pos=wx.DefaultPosition, sz=wx.DefaultSize):
        dialog = wx.FileDialog(self, message, defaultDir, defaultFile, wildcard,
                               style, pos, sz)
        result = dialog.ShowModal()
        dialog.Destroy()
        return dialog.Path if result == wx.ID_OK else None
    
    def dirDialog(self, message="Choose a directory", defaultPath="",
                  style=wx.DD_DEFAULT_STYLE, pos=wx.DefaultPosition,
                  size=wx.DefaultSize):
        dialog = wx.DirDialog(self, message, defaultPath, style, pos, size)
        result = dialog.ShowModal()
        dialog.Destroy()
        return dialog.Path if result == wx.ID_OK else None
